package com.example.project.utils;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.content.Intent;

public class JsonParser {

	public static void parseConnectResponse(Intent intent, String response) throws JSONException{
		JSONObject jsonObject = new JSONObject(response);
		
		// Put token in intent
		intent.putExtra("token", jsonObject.get("token").toString());
		
		// Put exam list in intent
		JSONArray jsonArray = jsonObject.getJSONArray("exams");
		int length = jsonArray.length();
		String[] examArray = new String[length];
		for (int i=0; i<length; i++){
			examArray[i] = jsonArray.getString(i);
		}
		intent.putExtra("exams", examArray);
	}
}
